home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / dosrcss.zip / IDENT.C < prev    next >
C/C++ Source or Header  |  1990-07-18  |  6KB  |  226 lines

  1. /* Copyright (C) 1982, 1988, 1989 Walter Tichy
  2.    Distributed under license by the Free Software Foundation, Inc.
  3.  
  4. This file is part of RCS.
  5.  
  6. RCS is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. RCS is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with RCS; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20. Report problems and direct all questions to:
  21.  
  22.     rcs-bugs@cs.purdue.edu
  23.  
  24. */
  25.  
  26. /*
  27.  *                     RCS identification operation
  28.  */
  29. #ifndef lint
  30. static char rcsid[]=
  31. "$Header: /site/tmp/dosrcs/src/RCS/ident.c,v 5.3 90/07/15 20:23:52 lfk Release $Purdue CS";
  32. #endif
  33.  
  34. /* $Log:    ident.c,v $
  35.  * Revision 5.3  90/07/15  20:23:52  lfk
  36.  * Most major fixes added between rev 5.1 and rev 5.5:
  37.  *     signals fixed so they work on MS-DOS
  38.  *     Added MKS arguments code so argv can be large
  39.  *     added code to handle slashes a'la Unix
  40.  *     added more file extensions to system from MS-DOS
  41.  * 
  42.  * Revision 5.2  90/07/15  11:31:31  ROOT_DOS
  43.  * DOS version of RCS 4.0 checked in for MODS
  44.  * by lfk@athena.mit.edu
  45.  * Also update to MSC 6.0
  46.  * 
  47.  * Revision 4.5  89/05/01  15:11:54  narten
  48.  * changed copyright header to reflect current distribution rules
  49.  * 
  50.  * Revision 4.4  87/10/23  17:09:57  narten
  51.  * added exit(0) so exit return code would be non random
  52.  * 
  53.  * Revision 4.3  87/10/18  10:23:55  narten
  54.  * Updating version numbers. Changes relative to 1.1 are actually relative
  55.  * to 4.1
  56.  * 
  57.  * Revision 1.3  87/07/09  09:20:52  trinkle
  58.  * Added check to make sure there is at least one arg before comparing argv[1]
  59.  * with "-q".  This necessary on machines that don't allow dereferncing null
  60.  * pointers (i.e. Suns).
  61.  * 
  62.  * Revision 1.2  87/03/27  14:21:47  jenkins
  63.  * Port to suns
  64.  * 
  65.  * Revision 1.1  84/01/23  14:50:03  kcs
  66.  * Initial revision
  67.  * 
  68.  * Revision 4.1  83/05/10  16:31:02  wft
  69.  * Added option -q and input from reading stdin.
  70.  * Marker matching is now done with trymatch() (independent of keywords).
  71.  * 
  72.  * Revision 3.4  83/02/18  17:37:49  wft
  73.  * removed printing of new line after last file.
  74.  *
  75.  * Revision 3.3  82/12/04  12:48:55  wft
  76.  * Added LOCKER.
  77.  *
  78.  * Revision 3.2  82/11/28  18:24:17  wft
  79.  * removed Suffix; added ungetc to avoid skipping over trailing KDELIM.
  80.  *
  81.  * Revision 3.1  82/10/13  15:58:51  wft
  82.  * fixed type of variables receiving from getc() (char-->int).
  83. */
  84.  
  85. #include  "rcsbase.h"
  86. #define fflsbuf _flsbuf
  87. /* redefinition of _flsbuf in putc not needed */
  88. #ifndef lint
  89. static char rcsbaseid[] = RCSBASE;
  90. #endif
  91.  
  92. extern enum markers trymatch();
  93.  
  94. int quietflag;
  95.  
  96. #ifdef MKS
  97. main(int argc, char *argv[], char *env[])
  98. #else
  99. main (argc, argv)
  100. int argc;
  101. char * argv[];
  102. #endif /* MKS */
  103. /*  Ident searches the named files for all occurrences
  104.  *  of the pattern $keyword:...$, where the keywords are
  105.  *  Author, Date, Header, Id, Log, RCSfile, Revision, Source, and State.
  106.  */
  107.  
  108. {
  109.    FILE *fp, *fopen();
  110. #ifdef MKS
  111.     int z = 0;
  112.     int ARGC = 0;
  113.     char **tmp;
  114.     char *env_name;
  115. #    define MAXARGS 500        /* This means 500 items on the command line */
  116.     if (!(tmp = (char **)malloc(sizeof(char *)*(MAXARGS+1)))) {
  117.         fprintf(stderr, "%s: can't allocate space for arguments\n",argv[0]);
  118.         exit(1);
  119.     }
  120.     for ( z = 0 ; env[z] != NULL; z++) {    /* loop through environment */
  121.         if (*env[z] == '~') {    /* testing for entries begining with '~' */
  122.             *++env[z];            /* increment pointer to delete '~' */
  123.             tmp[ARGC++] = env[z];    /* add it to our new array */
  124.             if (z >= MAXARGS) {
  125.                 fprintf(stderr, "%s: can't handle any more arguments\n", argv[0]);
  126.                 goto list;
  127.             }
  128.         }
  129.         else if (*env[z] == '_') {    /* testing for entries begining with _ */
  130.             *++env[z] ; *++env[z];    /* move past the '_' and the '=' */
  131.             env_name = env[z];    /* copy the name */
  132.         }
  133.     }
  134. list:
  135.     if ( STREQ( (char *) argv[0] , env_name ) ) {    /* test name against startup args */
  136.         /* environment arguments meant for this program */
  137. #    ifdef DEBUG
  138.         printf("Using shell supplied args\n");
  139. #    endif
  140.         argc = ARGC;
  141.         tmp[ARGC] = NULL;    /* the terminal NULL */
  142.         argv = tmp;
  143.     }
  144. #    ifdef DEBUG
  145.     else 
  146.         printf("Using startup supplied args\n");
  147. #    endif /* debug */
  148. #endif /* MKS */
  149.  
  150.    quietflag = false;
  151.    if (argc > 1 && strcmp("-q",argv[1])==0) {
  152.         quietflag = true;
  153.         argc--; argv++;
  154.    }
  155.  
  156.    if (argc<2) {
  157.      if ((scanfile(stdin) == 0) && !quietflag)
  158.         VOID fprintf(stderr, "ident warning: no id keywords in input\n");
  159.     exit(0);
  160.    }
  161.  
  162.    while ( --argc > 0 ) {
  163. #ifdef MSDOS
  164.       if ( (fp = fopen(*++argv, "rb") ) == NULL ) {
  165. #else
  166.       if ( (fp = fopen(*++argv, "r") ) == NULL ) {
  167. #endif
  168.          VOID fprintf(stderr,  "ident error: can't open %s\n", *argv);
  169.          continue;
  170.       } else {
  171.          VOID printf( "%s:\n", *argv);   /*  print file name  */
  172.      if ((scanfile(fp) == 0) && !quietflag)
  173.         VOID fprintf(stderr, "ident warning: no id keywords in %s\n", *argv);
  174.      if (argc>1) putchar('\n');
  175.      VOID fclose(fp);
  176.       }
  177.    }
  178.    exit(0);
  179. }
  180.  
  181.  
  182. int scanfile(file)
  183. FILE * file;
  184. /* Function: scan an open file with descriptor file for keywords.
  185.  * Returns the number of matches.
  186.  */
  187. {
  188.    register int matchcount;
  189.    register int c;
  190.  
  191.  
  192.    matchcount = 0;
  193.    while( (c=getc(file)) != EOF) {
  194.       if ( (char)c==KDELIM)
  195.      matchcount += match(file);
  196.    }
  197.    return matchcount;
  198. }
  199.  
  200.  
  201.  
  202. match(fp)   /* group substring between two KDELIM's; then do pattern match */
  203. FILE *fp;
  204. {
  205.    char line[keyvallength];
  206.    register int c;
  207.    register char * tp;
  208.  
  209.    tp = line;
  210.    while( (c = getc(fp)) != KDELIM ) {
  211.       *tp++ = c;
  212.       if ( c==EOF || c=='\n' || tp>= line+keyvallength-2)
  213.          return(0);
  214.    }
  215.    *tp++ = c;     /*append trailing KDELIM*/
  216.    *tp   = '\0';
  217.    if (trymatch(line,true)!=Nomatch) {
  218.         VOID fprintf(stdout,"     $%s\n",line);
  219.         return(1);
  220.    } else {
  221.       /* no match; put trailing KDELIM back into input */
  222.       VOID ungetc(c,fp );
  223.       return(0);
  224.    }
  225. }
  226.